# Copyright (c) 2017 Presto Labs Pte. Ltd.
# Author: jaewon


def to_list(x):
  if isinstance(x, list):
    return x
  return [x]


def to_tuple(x):
  if isinstance(x, tuple):
    return x
  elif isinstance(x, list):
    return tuple(x)
  else:
    return tuple([x])


def split_string(string, delimeter=','):
  ret = []
  if string is not None:
   ret = [elem.strip() for elem in string.split(delimeter)]
  return ret


def filter_duplicate(iterable, *, key_func=None):
  if key_func is None:
    return iterable
  key_set = set()
  filtered = []
  for elem in iterable:
    if key_func(elem) not in key_set:
      key_set.add(key_func(elem))
      filtered.append(elem)
  return filtered
